<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>地址管理</title>
    <link rel="shortcut icon" type="image/x-icon" th:href="@{../../static/img/index/bitbug_favicon.ico}"/>
    <link rel="stylesheet" th:href="@{../../static/css/bootstrap.css}"/>
    <link rel="stylesheet" th:href="@{../../static/css/user/set.css}"/>
    <script th:src="@{../../static/js/jquery-2.1.0.js}" type="text/javascript" charset="utf-8"></script>
    <script th:src="@{../../static/js/bootstrap.js}" type="text/javascript" charset="utf-8"></script>
    <script th:src="@{../../static/js/pay.js}" type="text/javascript" charset="utf-8"></script>
    <script th:src="@{../../static/js/jquery.Area.js}" type="text/javascript" charset="utf-8"></script>
    <script>
        $(function () {
            init_area();
            $('#addForm').submit(function () {
                if ($('#iDo-province').val() === '-1' && $('#iDo-city').val() === '-1' && $('#iDo-county').val() === '-1') {
                    alert("请选择地址信息");
                    return false;
                }
            })
            $('.edit').click(function () {
                console.log($(this).attr("data-id"));
                $.ajax({
                    url: "/user/editAdd",
                    type: "get",
                    data: {
                        addid: $(this).attr("data-id")
                    },
                    success: function (res) {
                        console.log(res);
                        $('[value =' + res.province + ']').attr("selected", true);
                        $('#iDo-province').trigger("change");
                        $('[value =' + res.city + ']').attr("selected", true);
                        $('#iDo-city').trigger("change");
                        $('[value =' + res.county + ']').attr("selected", true);
                        $('[name="address"]').val(res.address);
                        $('[name="name"]').val(res.name);
                        $('[name="mobile"]').val(res.mobile);
                        $('#addId').val(res.id);
                        if (res.defaultadd === "1") {
                            $('#default').trigger("click");
                        }
                        $('#addForm').attr("action", "/user/updateAdd");
                    }

                })
            })
        });
    </script>
</head>
<body>
<!--首页头部-->
<nav class="navbar navbar-default navbar-inverse navbar-fixed-top">
    <div class="container">
        <ul class="nav navbar-nav">
            <li>
                <a th:href="@{/go/index}" style="font-size: 30px; font-family:'楷体';">宠物商城</a>
            </li>
            <li th:if="${session.login_user!=null}">
                <a href="#" th:text="'欢迎您 :'+${session.login_user.getUsername()}"></a>
            </li>
            <li th:if="${session.login_user!=null}">
                <a th:href="@{'/user/set/'+${session.login_user.getId()}}">个人中心</a>
            </li>
            <li th:if="${session.login_user!=null}">
                <a th:href="@{/user/logout}">注销</a>
            </li>
        </ul>
    </div>
</nav>
<!--新增地址-->
<div class="container" style="margin-top:70px;">
    <div class="panel panel-info">
        <div class="panel-heading">
            地址详情
        </div>
        <div class="panel-body">
            <form th:action="@{/user/newAdd}" class="col-lg-8" id="addForm">
                <p class="iDo-info-p">
                    <input id="addId" name="id">
                    <span class="iDo-info-title">选择省市：</span>
                    <span class="iDo-info-box iDo-info-select">
                        <label id="province"><select class="form-control" id="iDo-province" name="province"><option
                                value="-1">--请选择--</option></select></label><span class="iDo-sc"></span>
                        <label id="city"><select class="form-control" id="iDo-city" name="city"><option
                                value="-1">--请选择--</option></select></label><span class="iDo-sc"></span>
                        <label id="county"><select class="form-control" id="iDo-county" name="county"><option
                                value="-1">--请选择--</option></select></label>
                    </span>
                    <span class="iDo-cl"></span>
                </p>
                <input type="text" placeholder="地址信息" name="address" class="form-control" required/><br/>
                <input type="text" placeholder="收货人姓名" name="name" class="form-control" required/><br/>
                <input type="tel" maxlength="11" minlength="11" required placeholder="手机电话" name="mobile"
                       class="form-control"/><br/>
                <p class="Switch">
                    <input type="checkbox" name="defaultadd" id="date"/>
                    <label for="date" id="default"><em></em></label>
                    设为默认地址
                </p>
                <br/><br/>
                <button class="btn btn-primary" type="submit">保存</button>
            </form>
        </div>
    </div>
</div>
<hr/>
<!--地址管理-->
<div class="container">
    <div class="panel panel-info">
        <div class="panel-heading">
            管理地址
        </div>
        <div class="panel-body">
            <table class="table table-bordered">
                <tr>
                    <th>收货人</th>
                    <th>地址</th>
                    <th>手机电话</th>
                    <th>操作</th>
                    <th>默认</th>
                </tr>
                <tr th:each="addinfo:${addinfos}">
                    <td th:text="${addinfo.getName()}">尹政南</td>
                    <td th:text="${addinfo.getProvince()+addinfo.getCity()+addinfo.getCounty()+addinfo.getAddress()}">
                        辽宁省沈阳市浑南新区世纪路新秀街东软睿道实训中心A9楼
                    </td>
                    <td th:text="${addinfo.getMobile()}">86-18*******97</td>
                    <td><a href="#" class="edit" th:attr="data-id=${addinfo.getId()}">修改</a> | <a
                            th:href="@{'/user/deleteAdd/'+${addinfo.getId()}}">删除</a></td>
                    <td><a th:if="${addinfo.getDefaultadd() == '1'}" class="btn btn-danger btn-xs">默认地址</a>
                    </td>
                </tr>
            </table>
        </div>
    </div>
</div>
</body>
</html>
